{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "624a40e7-de43-4c51-8e2e-d2eea73ceb8d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from mindsponge import Sponge\n",
    "from mindsponge import ForceField\n",
    "from mindsponge.optimizer import SteepestDescent\n",
    "from mindsponge.callback import WriteH5MD, RunInfo\n",
    "from mindsponge import set_global_units\n",
    "from mindsponge import Protein\n",
    "from mindsponge import UpdaterMD\n",
    "from mindsponge.function import VelocityGenerator\n",
    "from mindspore import context"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5e67abd9",
   "metadata": {},
   "outputs": [],
   "source": [
    "context.set_context(mode=context.PYNATIVE_MODE, device_target=\"GPU\")"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "8b9397c0-5a6a-4338-9fa4-5b5ce46e0e58",
   "metadata": {},
   "source": [
    "## 单位设置\n",
    "\n",
    "这里我们提到的全局单位设置，主要是指输入输出的长度单位和能量单位，在MindSPONGE的计算过程中会自动根据默认单位进行计算，再将返回的结果转换成用户定义的单位。常用的长度单位是nm和A，一般在PDB文件里面是用A为单位。能量单位比较常用的是kJ/mol和kcal/mol。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c6bfe6a3-1f67-40ed-ba0d-33c0168c3f79",
   "metadata": {},
   "outputs": [],
   "source": [
    "set_global_units('nm', 'kj/mol')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "83cbf326-a968-4cf5-a405-1ba7c97576d6",
   "metadata": {},
   "source": [
    "## 蛋白质案例\n",
    "\n",
    "我们提供了一些简单的蛋白质案例以供测试，一般用pdb(Protein Data Bank)格式来存储蛋白质文件。下述案例就是一个不含H原子的pdb文件（该构象来自于MEGAProtein的预测结果）。\n",
    "\n",
    "![](../../docs/case2-1.png)\n",
    "\n",
    "在使用MindSPONGE构建Protein对象时，会自动为其在相对合理的位置补充H原子（如下图所示）。而这一过程之后，最好对其进行一次能量最小化的操作，以确保得到的构象中不会存在太多的冲突，比如两个原子距离太近等。\n",
    "\n",
    "![](../../docs/case2-3.png)\n",
    "\n",
    "如果使用常用的蛋白质可视化算法NewCartoon来展示的话，可以更清晰的看到这个构象中所存在的$\\alpha$螺旋和$\\beta$折叠等区域：\n",
    "\n",
    "![](../../docs/case2-2.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "66371d6d-a10c-47ff-99fb-6568f64ccddf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Adding 2529 hydrogen atoms for the protein molecule in 1.113 seconds.\n"
     ]
    }
   ],
   "source": [
    "pdb_name = 'case2.pdb'\n",
    "system = Protein(pdb=pdb_name, rebuild_hydrogen=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1d313558-c263-4324-9a44-459dd2335de1",
   "metadata": {},
   "outputs": [],
   "source": [
    "energy = ForceField(system, 'AMBER.FF14SB')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7d85face-7806-4ee4-8f24-2889f073a099",
   "metadata": {},
   "outputs": [],
   "source": [
    "min_opt = SteepestDescent(system.trainable_params(), 1e-7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "07ff76ae-4624-4fa4-92d3-e98d24638206",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Using fully connected neighbour list (not updated).\n"
     ]
    }
   ],
   "source": [
    "md = Sponge(system, energy, min_opt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "51d64e25-7d63-46e0-977a-b0626b1ed361",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Started simulation at 2023-06-30 16:48:59\n",
      "[MindSPONGE] Step: 0, E_pot: 141277.78\n",
      "[MindSPONGE] Step: 10, E_pot: 96861.06\n",
      "[MindSPONGE] Step: 20, E_pot: 75968.81\n",
      "[MindSPONGE] Step: 30, E_pot: 62559.87\n",
      "[MindSPONGE] Step: 40, E_pot: 53021.83\n",
      "[MindSPONGE] Step: 50, E_pot: 45810.742\n",
      "[MindSPONGE] Step: 60, E_pot: 40129.08\n",
      "[MindSPONGE] Step: 70, E_pot: 35518.984\n",
      "[MindSPONGE] Step: 80, E_pot: 31696.498\n",
      "[MindSPONGE] Step: 90, E_pot: 28473.77\n",
      "[MindSPONGE] Step: 100, E_pot: 25719.998\n",
      "[MindSPONGE] Step: 110, E_pot: 23340.135\n",
      "[MindSPONGE] Step: 120, E_pot: 21262.908\n",
      "[MindSPONGE] Step: 130, E_pot: 19433.643\n",
      "[MindSPONGE] Step: 140, E_pot: 17809.637\n",
      "[MindSPONGE] Step: 150, E_pot: 16357.127\n",
      "[MindSPONGE] Step: 160, E_pot: 15049.16\n",
      "[MindSPONGE] Step: 170, E_pot: 13864.028\n",
      "[MindSPONGE] Step: 180, E_pot: 12784.107\n",
      "[MindSPONGE] Step: 190, E_pot: 11794.958\n",
      "[MindSPONGE] Step: 200, E_pot: 10884.639\n",
      "[MindSPONGE] Step: 210, E_pot: 10043.269\n",
      "[MindSPONGE] Step: 220, E_pot: 9262.627\n",
      "[MindSPONGE] Step: 230, E_pot: 8535.753\n",
      "[MindSPONGE] Step: 240, E_pot: 7856.762\n",
      "[MindSPONGE] Step: 250, E_pot: 7220.604\n",
      "[MindSPONGE] Step: 260, E_pot: 6622.9824\n",
      "[MindSPONGE] Step: 270, E_pot: 6060.175\n",
      "[MindSPONGE] Step: 280, E_pot: 5528.9463\n",
      "[MindSPONGE] Step: 290, E_pot: 5026.491\n",
      "[MindSPONGE] Step: 300, E_pot: 4550.3047\n",
      "[MindSPONGE] Step: 310, E_pot: 4098.2305\n",
      "[MindSPONGE] Step: 320, E_pot: 3668.3389\n",
      "[MindSPONGE] Step: 330, E_pot: 3258.938\n",
      "[MindSPONGE] Step: 340, E_pot: 2868.4795\n",
      "[MindSPONGE] Step: 350, E_pot: 2495.6018\n",
      "[MindSPONGE] Step: 360, E_pot: 2139.0647\n",
      "[MindSPONGE] Step: 370, E_pot: 1797.7935\n",
      "[MindSPONGE] Step: 380, E_pot: 1470.7488\n",
      "[MindSPONGE] Step: 390, E_pot: 1157.033\n",
      "[MindSPONGE] Step: 400, E_pot: 855.81494\n",
      "[MindSPONGE] Step: 410, E_pot: 566.34204\n",
      "[MindSPONGE] Step: 420, E_pot: 287.9038\n",
      "[MindSPONGE] Step: 430, E_pot: 19.882324\n",
      "[MindSPONGE] Step: 440, E_pot: -238.31213\n",
      "[MindSPONGE] Step: 450, E_pot: -487.24072\n",
      "[MindSPONGE] Step: 460, E_pot: -727.4009\n",
      "[MindSPONGE] Step: 470, E_pot: -959.2655\n",
      "[MindSPONGE] Step: 480, E_pot: -1183.2631\n",
      "[MindSPONGE] Step: 490, E_pot: -1399.7916\n",
      "[MindSPONGE] Finished simulation at 2023-06-30 16:49:52\n",
      "[MindSPONGE] Simulation time: 53.46 seconds.\n",
      "--------------------------------------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<mindsponge.core.sponge.Sponge at 0x7f922b46da90>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "run_info = RunInfo(10)\n",
    "md.run(500, callbacks=[run_info])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ee6d410b-a152-4785-9a67-322996b09bfd",
   "metadata": {},
   "outputs": [],
   "source": [
    "vgen = VelocityGenerator(300)\n",
    "velocity = vgen(system.shape, system.atom_mass)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a4208b35-3d46-4b71-9144-f0e8d6959f74",
   "metadata": {},
   "outputs": [],
   "source": [
    "opt = UpdaterMD(system=system,\n",
    "                time_step=1e-3,\n",
    "                velocity=velocity,\n",
    "                integrator='velocity_verlet',\n",
    "                temperature=300,\n",
    "                thermostat='langevin',)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0a7bcba5-5ac0-4f46-94aa-f078f3e3ffb1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Using fully connected neighbour list (not updated).\n"
     ]
    }
   ],
   "source": [
    "md = Sponge(system, energy, min_opt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "bf16e327-09fb-42dd-91ea-320b9acad87d",
   "metadata": {},
   "outputs": [],
   "source": [
    "cb_h5md = WriteH5MD(system, 'tutorial_b06.h5md', save_freq=10, write_velocity=True, write_force=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c1084b9b-4df7-46c0-8a34-ccb19df6a153",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MindSPONGE] Started simulation at 2023-06-30 16:50:02\n",
      "[MindSPONGE] Step: 0, E_pot: -1609.2458, E_kin: 9305.716, E_tot: 7696.4697, Temperature: 295.15308\n",
      "[MindSPONGE] Step: 10, E_pot: -2079.5398, E_kin: 9494.258, E_tot: 7414.718, Temperature: 301.13312\n",
      "[MindSPONGE] Step: 20, E_pot: -3061.2454, E_kin: 11006.04, E_tot: 7944.795, Temperature: 349.08292\n",
      "[MindSPONGE] Step: 30, E_pot: -1711.0934, E_kin: 9731.676, E_tot: 8020.5825, Temperature: 308.6634\n",
      "[MindSPONGE] Step: 40, E_pot: -3201.4827, E_kin: 11231.6455, E_tot: 8030.163, Temperature: 356.23853\n",
      "[MindSPONGE] Step: 50, E_pot: -2869.9229, E_kin: 10555.592, E_tot: 7685.669, Temperature: 334.79587\n",
      "[MindSPONGE] Step: 60, E_pot: -3077.96, E_kin: 10582.215, E_tot: 7504.255, Temperature: 335.6403\n",
      "[MindSPONGE] Step: 70, E_pot: -3289.6162, E_kin: 10907.554, E_tot: 7617.9375, Temperature: 345.95917\n",
      "[MindSPONGE] Step: 80, E_pot: -2895.5718, E_kin: 10423.396, E_tot: 7527.8247, Temperature: 330.60297\n",
      "[MindSPONGE] Step: 90, E_pot: -3566.5032, E_kin: 10968.898, E_tot: 7402.3955, Temperature: 347.90488\n",
      "[MindSPONGE] Step: 100, E_pot: -3456.4294, E_kin: 10620.159, E_tot: 7163.7295, Temperature: 336.84378\n",
      "[MindSPONGE] Step: 110, E_pot: -3535.6328, E_kin: 10495.357, E_tot: 6959.7246, Temperature: 332.8854\n",
      "[MindSPONGE] Step: 120, E_pot: -3863.9321, E_kin: 10641.503, E_tot: 6777.571, Temperature: 337.52075\n",
      "[MindSPONGE] Step: 130, E_pot: -3862.9856, E_kin: 10691.975, E_tot: 6828.9893, Temperature: 339.12155\n",
      "[MindSPONGE] Step: 140, E_pot: -4025.2275, E_kin: 10814.675, E_tot: 6789.4473, Temperature: 343.0133\n",
      "[MindSPONGE] Step: 150, E_pot: -3924.6274, E_kin: 10570.67, E_tot: 6646.0425, Temperature: 335.2741\n",
      "[MindSPONGE] Step: 160, E_pot: -4275.529, E_kin: 10593.364, E_tot: 6317.8354, Temperature: 335.9939\n",
      "[MindSPONGE] Step: 170, E_pot: -4160.6035, E_kin: 10287.944, E_tot: 6127.341, Temperature: 326.30676\n",
      "[MindSPONGE] Step: 180, E_pot: -4549.241, E_kin: 10419.344, E_tot: 5870.1025, Temperature: 330.47443\n",
      "[MindSPONGE] Step: 190, E_pot: -4560.417, E_kin: 10239.507, E_tot: 5679.09, Temperature: 324.77048\n",
      "[MindSPONGE] Step: 200, E_pot: -4588.139, E_kin: 9931.78, E_tot: 5343.641, Temperature: 315.0102\n",
      "[MindSPONGE] Step: 210, E_pot: -4704.2227, E_kin: 9991.355, E_tot: 5287.133, Temperature: 316.89978\n",
      "[MindSPONGE] Step: 220, E_pot: -4559.415, E_kin: 9943.885, E_tot: 5384.4697, Temperature: 315.39413\n",
      "[MindSPONGE] Step: 230, E_pot: -4534.7305, E_kin: 9860.407, E_tot: 5325.677, Temperature: 312.74643\n",
      "[MindSPONGE] Step: 240, E_pot: -4673.7065, E_kin: 10023.802, E_tot: 5350.095, Temperature: 317.92886\n",
      "[MindSPONGE] Step: 250, E_pot: -4670.1885, E_kin: 9858.703, E_tot: 5188.5146, Temperature: 312.69238\n",
      "[MindSPONGE] Step: 260, E_pot: -4991.4146, E_kin: 10245.202, E_tot: 5253.7876, Temperature: 324.9511\n",
      "[MindSPONGE] Step: 270, E_pot: -5073.1846, E_kin: 10086.119, E_tot: 5012.9346, Temperature: 319.90543\n",
      "[MindSPONGE] Step: 280, E_pot: -5135.8677, E_kin: 9916.857, E_tot: 4780.9897, Temperature: 314.53687\n",
      "[MindSPONGE] Step: 290, E_pot: -4972.7676, E_kin: 9663.772, E_tot: 4691.005, Temperature: 306.50967\n",
      "[MindSPONGE] Step: 300, E_pot: -4991.468, E_kin: 9693.854, E_tot: 4702.3857, Temperature: 307.46378\n",
      "[MindSPONGE] Step: 310, E_pot: -5275.949, E_kin: 9904.248, E_tot: 4628.299, Temperature: 314.13693\n",
      "[MindSPONGE] Step: 320, E_pot: -5366.4243, E_kin: 9759.425, E_tot: 4393.0005, Temperature: 309.54352\n",
      "[MindSPONGE] Step: 330, E_pot: -5214.6104, E_kin: 9588.469, E_tot: 4373.8584, Temperature: 304.12125\n",
      "[MindSPONGE] Step: 340, E_pot: -5229.7334, E_kin: 9608.612, E_tot: 4378.879, Temperature: 304.76013\n",
      "[MindSPONGE] Step: 350, E_pot: -5320.184, E_kin: 9607.355, E_tot: 4287.1714, Temperature: 304.72028\n",
      "[MindSPONGE] Step: 360, E_pot: -5083.007, E_kin: 9404.453, E_tot: 4321.4463, Temperature: 298.28473\n",
      "[MindSPONGE] Step: 370, E_pot: -5446.1646, E_kin: 9725.172, E_tot: 4279.0073, Temperature: 308.45712\n",
      "[MindSPONGE] Step: 380, E_pot: -5412.706, E_kin: 9812.403, E_tot: 4399.6973, Temperature: 311.22388\n",
      "[MindSPONGE] Step: 390, E_pot: -5417.179, E_kin: 9777.371, E_tot: 4360.192, Temperature: 310.11273\n",
      "[MindSPONGE] Step: 400, E_pot: -5079.777, E_kin: 9446.167, E_tot: 4366.39, Temperature: 299.60782\n",
      "[MindSPONGE] Step: 410, E_pot: -5397.0415, E_kin: 9938.77, E_tot: 4541.728, Temperature: 315.23187\n",
      "[MindSPONGE] Step: 420, E_pot: -5380.2627, E_kin: 9704.275, E_tot: 4324.0127, Temperature: 307.7943\n",
      "[MindSPONGE] Step: 430, E_pot: -5435.5024, E_kin: 9786.717, E_tot: 4351.2144, Temperature: 310.40915\n",
      "[MindSPONGE] Step: 440, E_pot: -5336.742, E_kin: 9580.732, E_tot: 4243.99, Temperature: 303.87585\n",
      "[MindSPONGE] Step: 450, E_pot: -5432.657, E_kin: 9574.461, E_tot: 4141.8037, Temperature: 303.67697\n",
      "[MindSPONGE] Step: 460, E_pot: -5385.355, E_kin: 9378.014, E_tot: 3992.6587, Temperature: 297.44617\n",
      "[MindSPONGE] Step: 470, E_pot: -5353.1875, E_kin: 9429.458, E_tot: 4076.2705, Temperature: 299.07785\n",
      "[MindSPONGE] Step: 480, E_pot: -5556.608, E_kin: 9666.612, E_tot: 4110.0044, Temperature: 306.59976\n",
      "[MindSPONGE] Step: 490, E_pot: -5608.713, E_kin: 9694.4375, E_tot: 4085.7246, Temperature: 307.4823\n",
      "[MindSPONGE] Step: 500, E_pot: -5732.911, E_kin: 9536.721, E_tot: 3803.8096, Temperature: 302.47992\n",
      "[MindSPONGE] Step: 510, E_pot: -5663.5083, E_kin: 9546.148, E_tot: 3882.6401, Temperature: 302.77893\n",
      "[MindSPONGE] Step: 520, E_pot: -5496.2627, E_kin: 9514.603, E_tot: 4018.3398, Temperature: 301.7784\n",
      "[MindSPONGE] Step: 530, E_pot: -5612.2764, E_kin: 9561.05, E_tot: 3948.7734, Temperature: 303.2516\n",
      "[MindSPONGE] Step: 540, E_pot: -5534.0396, E_kin: 9487.432, E_tot: 3953.392, Temperature: 300.9166\n",
      "[MindSPONGE] Step: 550, E_pot: -5635.116, E_kin: 9435.01, E_tot: 3799.8936, Temperature: 299.25394\n",
      "[MindSPONGE] Step: 560, E_pot: -5735.0557, E_kin: 9569.258, E_tot: 3834.2021, Temperature: 303.5119\n",
      "[MindSPONGE] Step: 570, E_pot: -5612.3623, E_kin: 9532.836, E_tot: 3920.4736, Temperature: 302.3567\n",
      "[MindSPONGE] Step: 580, E_pot: -5565.037, E_kin: 9546.084, E_tot: 3981.0469, Temperature: 302.77692\n",
      "[MindSPONGE] Step: 590, E_pot: -5695.21, E_kin: 9440.334, E_tot: 3745.124, Temperature: 299.4228\n",
      "[MindSPONGE] Step: 600, E_pot: -5571.8457, E_kin: 9472.555, E_tot: 3900.709, Temperature: 300.44476\n",
      "[MindSPONGE] Step: 610, E_pot: -5919.6743, E_kin: 9781.455, E_tot: 3861.7808, Temperature: 310.24225\n",
      "[MindSPONGE] Step: 620, E_pot: -5671.205, E_kin: 9467.86, E_tot: 3796.6553, Temperature: 300.29584\n",
      "[MindSPONGE] Step: 630, E_pot: -5756.402, E_kin: 9716.003, E_tot: 3959.601, Temperature: 308.1663\n",
      "[MindSPONGE] Step: 640, E_pot: -5917.4873, E_kin: 9770.97, E_tot: 3853.4824, Temperature: 309.9097\n",
      "[MindSPONGE] Step: 650, E_pot: -5911.0376, E_kin: 9639.466, E_tot: 3728.4282, Temperature: 305.73874\n",
      "[MindSPONGE] Step: 660, E_pot: -5927.2783, E_kin: 9629.742, E_tot: 3702.4639, Temperature: 305.43033\n",
      "[MindSPONGE] Step: 670, E_pot: -5919.7607, E_kin: 9587.631, E_tot: 3667.87, Temperature: 304.09467\n",
      "[MindSPONGE] Step: 680, E_pot: -5875.2266, E_kin: 9515.097, E_tot: 3639.87, Temperature: 301.79407\n",
      "[MindSPONGE] Step: 690, E_pot: -5755.2534, E_kin: 9392.794, E_tot: 3637.5405, Temperature: 297.91495\n",
      "[MindSPONGE] Step: 700, E_pot: -5972.0967, E_kin: 9471.354, E_tot: 3499.2568, Temperature: 300.40665\n",
      "[MindSPONGE] Step: 710, E_pot: -5987.2803, E_kin: 9370.385, E_tot: 3383.1045, Temperature: 297.20416\n",
      "[MindSPONGE] Step: 720, E_pot: -6130.566, E_kin: 9486.223, E_tot: 3355.6567, Temperature: 300.87827\n",
      "[MindSPONGE] Step: 730, E_pot: -6167.8867, E_kin: 9481.137, E_tot: 3313.25, Temperature: 300.71695\n",
      "[MindSPONGE] Step: 740, E_pot: -6014.826, E_kin: 9243.809, E_tot: 3228.9824, Temperature: 293.1895\n",
      "[MindSPONGE] Step: 750, E_pot: -5964.629, E_kin: 9319.204, E_tot: 3354.5752, Temperature: 295.58087\n",
      "[MindSPONGE] Step: 760, E_pot: -5965.502, E_kin: 9408.189, E_tot: 3442.6875, Temperature: 298.40326\n",
      "[MindSPONGE] Step: 770, E_pot: -6157.116, E_kin: 9435.512, E_tot: 3278.3955, Temperature: 299.26984\n",
      "[MindSPONGE] Step: 780, E_pot: -6122.6284, E_kin: 9262.23, E_tot: 3139.602, Temperature: 293.77383\n",
      "[MindSPONGE] Step: 790, E_pot: -6216.1494, E_kin: 9446.154, E_tot: 3230.005, Temperature: 299.60742\n",
      "[MindSPONGE] Step: 800, E_pot: -6139.991, E_kin: 9311.369, E_tot: 3171.378, Temperature: 295.33237\n",
      "[MindSPONGE] Step: 810, E_pot: -6159.3022, E_kin: 9418.305, E_tot: 3259.0024, Temperature: 298.72406\n",
      "[MindSPONGE] Step: 820, E_pot: -6170.4204, E_kin: 9652.463, E_tot: 3482.0425, Temperature: 306.15097\n",
      "[MindSPONGE] Step: 830, E_pot: -6322.676, E_kin: 9737.393, E_tot: 3414.7168, Temperature: 308.84473\n",
      "[MindSPONGE] Step: 840, E_pot: -6177.9473, E_kin: 9393.639, E_tot: 3215.6914, Temperature: 297.94174\n",
      "[MindSPONGE] Step: 850, E_pot: -6187.0493, E_kin: 9363.098, E_tot: 3176.0483, Temperature: 296.97305\n",
      "[MindSPONGE] Step: 860, E_pot: -6123.078, E_kin: 9320.816, E_tot: 3197.7383, Temperature: 295.632\n",
      "[MindSPONGE] Step: 870, E_pot: -6096.9453, E_kin: 9358.457, E_tot: 3261.5117, Temperature: 296.82587\n",
      "[MindSPONGE] Step: 880, E_pot: -6123.2437, E_kin: 9422.73, E_tot: 3299.4868, Temperature: 298.86447\n",
      "[MindSPONGE] Step: 890, E_pot: -6260.7295, E_kin: 9511.795, E_tot: 3251.0654, Temperature: 301.68933\n",
      "[MindSPONGE] Step: 900, E_pot: -5986.88, E_kin: 9372.367, E_tot: 3385.4873, Temperature: 297.26706\n",
      "[MindSPONGE] Step: 910, E_pot: -6118.1987, E_kin: 9558.19, E_tot: 3439.9917, Temperature: 303.1609\n",
      "[MindSPONGE] Step: 920, E_pot: -6008.8086, E_kin: 9399.108, E_tot: 3390.2998, Temperature: 298.1152\n",
      "[MindSPONGE] Step: 930, E_pot: -6084.8936, E_kin: 9548.967, E_tot: 3464.0732, Temperature: 302.86835\n",
      "[MindSPONGE] Step: 940, E_pot: -6157.6646, E_kin: 9463.863, E_tot: 3306.1987, Temperature: 300.16907\n",
      "[MindSPONGE] Step: 950, E_pot: -6240.39, E_kin: 9503.707, E_tot: 3263.317, Temperature: 301.43283\n",
      "[MindSPONGE] Step: 960, E_pot: -6177.811, E_kin: 9395.638, E_tot: 3217.8267, Temperature: 298.00513\n",
      "[MindSPONGE] Step: 970, E_pot: -6060.975, E_kin: 9419.354, E_tot: 3358.3784, Temperature: 298.75732\n",
      "[MindSPONGE] Step: 980, E_pot: -6350.5454, E_kin: 9435.299, E_tot: 3084.7534, Temperature: 299.2631\n",
      "[MindSPONGE] Step: 990, E_pot: -6260.484, E_kin: 9319.115, E_tot: 3058.6313, Temperature: 295.57806\n",
      "[MindSPONGE] Step: 1000, E_pot: -6175.7935, E_kin: 9316.845, E_tot: 3141.0513, Temperature: 295.50604\n",
      "[MindSPONGE] Step: 1010, E_pot: -6202.956, E_kin: 9296.975, E_tot: 3094.0186, Temperature: 294.87582\n",
      "[MindSPONGE] Step: 1020, E_pot: -6275.3735, E_kin: 9382.491, E_tot: 3107.1177, Temperature: 297.58817\n",
      "[MindSPONGE] Step: 1030, E_pot: -6041.686, E_kin: 9066.102, E_tot: 3024.4155, Temperature: 287.55313\n",
      "[MindSPONGE] Step: 1040, E_pot: -6125.3984, E_kin: 9363.615, E_tot: 3238.2168, Temperature: 296.98947\n",
      "[MindSPONGE] Step: 1050, E_pot: -6119.5205, E_kin: 9389.442, E_tot: 3269.9219, Temperature: 297.80865\n",
      "[MindSPONGE] Step: 1060, E_pot: -6100.7397, E_kin: 9289.691, E_tot: 3188.9517, Temperature: 294.6448\n",
      "[MindSPONGE] Step: 1070, E_pot: -6203.6143, E_kin: 9457.809, E_tot: 3254.1943, Temperature: 299.97705\n",
      "[MindSPONGE] Step: 1080, E_pot: -6052.413, E_kin: 9479.575, E_tot: 3427.162, Temperature: 300.66742\n",
      "[MindSPONGE] Step: 1090, E_pot: -6012.337, E_kin: 9640.377, E_tot: 3628.04, Temperature: 305.76764\n",
      "[MindSPONGE] Step: 1100, E_pot: -5890.3936, E_kin: 9641.139, E_tot: 3750.745, Temperature: 305.79178\n",
      "[MindSPONGE] Step: 1110, E_pot: -5655.5654, E_kin: 9388.781, E_tot: 3733.2158, Temperature: 297.7877\n",
      "[MindSPONGE] Step: 1120, E_pot: -5931.858, E_kin: 9642.121, E_tot: 3710.2632, Temperature: 305.82297\n",
      "[MindSPONGE] Step: 1130, E_pot: -5738.1978, E_kin: 9435.99, E_tot: 3697.7925, Temperature: 299.285\n",
      "[MindSPONGE] Step: 1140, E_pot: -5912.4243, E_kin: 9463.426, E_tot: 3551.0015, Temperature: 300.15518\n",
      "[MindSPONGE] Step: 1150, E_pot: -6024.37, E_kin: 9511.256, E_tot: 3486.8857, Temperature: 301.67224\n",
      "[MindSPONGE] Step: 1160, E_pot: -5894.9785, E_kin: 9371.217, E_tot: 3476.2383, Temperature: 297.2306\n",
      "[MindSPONGE] Step: 1170, E_pot: -5932.542, E_kin: 9499.611, E_tot: 3567.0693, Temperature: 301.30292\n",
      "[MindSPONGE] Step: 1180, E_pot: -6318.114, E_kin: 9677.02, E_tot: 3358.9058, Temperature: 306.92984\n",
      "[MindSPONGE] Step: 1190, E_pot: -6367.4077, E_kin: 9580.035, E_tot: 3212.6274, Temperature: 303.85376\n",
      "[MindSPONGE] Step: 1200, E_pot: -6203.0957, E_kin: 9443.709, E_tot: 3240.6133, Temperature: 299.52985\n",
      "[MindSPONGE] Step: 1210, E_pot: -6235.3335, E_kin: 9193.819, E_tot: 2958.4858, Temperature: 291.604\n",
      "[MindSPONGE] Step: 1220, E_pot: -6300.929, E_kin: 9327.869, E_tot: 3026.94, Temperature: 295.85568\n",
      "[MindSPONGE] Step: 1230, E_pot: -6511.159, E_kin: 9469.055, E_tot: 2957.8955, Temperature: 300.33374\n",
      "[MindSPONGE] Step: 1240, E_pot: -6494.9727, E_kin: 9540.193, E_tot: 3045.2207, Temperature: 302.59006\n",
      "[MindSPONGE] Step: 1250, E_pot: -6487.899, E_kin: 9450.769, E_tot: 2962.8696, Temperature: 299.75375\n",
      "[MindSPONGE] Step: 1260, E_pot: -6213.845, E_kin: 9266.322, E_tot: 3052.477, Temperature: 293.9036\n",
      "[MindSPONGE] Step: 1270, E_pot: -6287.504, E_kin: 9338.682, E_tot: 3051.1777, Temperature: 296.19864\n",
      "[MindSPONGE] Step: 1280, E_pot: -6477.902, E_kin: 9607.45, E_tot: 3129.5483, Temperature: 304.7233\n",
      "[MindSPONGE] Step: 1290, E_pot: -6411.922, E_kin: 9492.09, E_tot: 3080.168, Temperature: 301.06433\n",
      "[MindSPONGE] Step: 1300, E_pot: -6267.633, E_kin: 9388.485, E_tot: 3120.8525, Temperature: 297.7783\n",
      "[MindSPONGE] Step: 1310, E_pot: -6146.513, E_kin: 9158.561, E_tot: 3012.0474, Temperature: 290.48566\n",
      "[MindSPONGE] Step: 1320, E_pot: -6196.05, E_kin: 9315.854, E_tot: 3119.8037, Temperature: 295.4746\n",
      "[MindSPONGE] Step: 1330, E_pot: -6102.8877, E_kin: 9391.492, E_tot: 3288.6045, Temperature: 297.87366\n",
      "[MindSPONGE] Step: 1340, E_pot: -6228.204, E_kin: 9448.824, E_tot: 3220.62, Temperature: 299.69208\n",
      "[MindSPONGE] Step: 1350, E_pot: -6085.7915, E_kin: 9331.623, E_tot: 3245.8315, Temperature: 295.97476\n",
      "[MindSPONGE] Step: 1360, E_pot: -6218.8057, E_kin: 9408.081, E_tot: 3189.2754, Temperature: 298.3998\n",
      "[MindSPONGE] Step: 1370, E_pot: -6259.961, E_kin: 9344.111, E_tot: 3084.1504, Temperature: 296.37088\n",
      "[MindSPONGE] Step: 1380, E_pot: -6298.2114, E_kin: 9242.332, E_tot: 2944.1206, Temperature: 293.14267\n",
      "[MindSPONGE] Step: 1390, E_pot: -6354.5693, E_kin: 9386.02, E_tot: 3031.4502, Temperature: 297.70007\n",
      "[MindSPONGE] Step: 1400, E_pot: -6334.9536, E_kin: 9354.512, E_tot: 3019.558, Temperature: 296.7007\n",
      "[MindSPONGE] Step: 1410, E_pot: -6234.0137, E_kin: 9182.257, E_tot: 2948.2432, Temperature: 291.23724\n",
      "[MindSPONGE] Step: 1420, E_pot: -6531.3184, E_kin: 9320.797, E_tot: 2789.4785, Temperature: 295.6314\n",
      "[MindSPONGE] Step: 1430, E_pot: -6592.8984, E_kin: 9393.436, E_tot: 2800.537, Temperature: 297.9353\n",
      "[MindSPONGE] Step: 1440, E_pot: -6346.5493, E_kin: 9337.041, E_tot: 2990.4917, Temperature: 296.1466\n",
      "[MindSPONGE] Step: 1450, E_pot: -6411.7627, E_kin: 9435.152, E_tot: 3023.3896, Temperature: 299.25842\n",
      "[MindSPONGE] Step: 1460, E_pot: -6375.2637, E_kin: 9405.692, E_tot: 3030.4287, Temperature: 298.32407\n",
      "[MindSPONGE] Step: 1470, E_pot: -6347.1816, E_kin: 9353.203, E_tot: 3006.0215, Temperature: 296.65924\n",
      "[MindSPONGE] Step: 1480, E_pot: -6278.6157, E_kin: 9264.541, E_tot: 2985.9253, Temperature: 293.84708\n",
      "[MindSPONGE] Step: 1490, E_pot: -6268.432, E_kin: 9288.455, E_tot: 3020.023, Temperature: 294.6056\n",
      "[MindSPONGE] Step: 1500, E_pot: -6357.7256, E_kin: 9405.924, E_tot: 3048.1982, Temperature: 298.3314\n",
      "[MindSPONGE] Step: 1510, E_pot: -6260.4277, E_kin: 9383.199, E_tot: 3122.7715, Temperature: 297.61063\n",
      "[MindSPONGE] Step: 1520, E_pot: -6061.983, E_kin: 9329.239, E_tot: 3267.2563, Temperature: 295.89917\n",
      "[MindSPONGE] Step: 1530, E_pot: -6170.6177, E_kin: 9488.604, E_tot: 3317.9858, Temperature: 300.95377\n",
      "[MindSPONGE] Step: 1540, E_pot: -6246.156, E_kin: 9451.004, E_tot: 3204.8481, Temperature: 299.76123\n",
      "[MindSPONGE] Step: 1550, E_pot: -6323.706, E_kin: 9578.428, E_tot: 3254.7217, Temperature: 303.80276\n",
      "[MindSPONGE] Step: 1560, E_pot: -6188.2554, E_kin: 9333.327, E_tot: 3145.0718, Temperature: 296.0288\n",
      "[MindSPONGE] Step: 1570, E_pot: -6323.272, E_kin: 9567.589, E_tot: 3244.317, Temperature: 303.45898\n",
      "[MindSPONGE] Step: 1580, E_pot: -6316.619, E_kin: 9518.219, E_tot: 3201.5996, Temperature: 301.89307\n",
      "[MindSPONGE] Step: 1590, E_pot: -6253.906, E_kin: 9426.986, E_tot: 3173.0806, Temperature: 298.99945\n",
      "[MindSPONGE] Step: 1600, E_pot: -6463.8774, E_kin: 9590.805, E_tot: 3126.9272, Temperature: 304.1953\n",
      "[MindSPONGE] Step: 1610, E_pot: -6468.0303, E_kin: 9556.55, E_tot: 3088.5195, Temperature: 303.10886\n",
      "[MindSPONGE] Step: 1620, E_pot: -6326.8086, E_kin: 9473.892, E_tot: 3147.083, Temperature: 300.48715\n",
      "[MindSPONGE] Step: 1630, E_pot: -6279.6094, E_kin: 9444.598, E_tot: 3164.9883, Temperature: 299.55804\n",
      "[MindSPONGE] Step: 1640, E_pot: -6126.1504, E_kin: 9277.629, E_tot: 3151.4785, Temperature: 294.2622\n",
      "[MindSPONGE] Step: 1650, E_pot: -6268.2124, E_kin: 9357.752, E_tot: 3089.5396, Temperature: 296.8035\n",
      "[MindSPONGE] Step: 1660, E_pot: -6373.433, E_kin: 9536.641, E_tot: 3163.2075, Temperature: 302.4774\n",
      "[MindSPONGE] Step: 1670, E_pot: -6253.0044, E_kin: 9416.3955, E_tot: 3163.391, Temperature: 298.66354\n",
      "[MindSPONGE] Step: 1680, E_pot: -6265.548, E_kin: 9345.36, E_tot: 3079.8125, Temperature: 296.41046\n",
      "[MindSPONGE] Step: 1690, E_pot: -6264.0024, E_kin: 9427.128, E_tot: 3163.1255, Temperature: 299.00394\n",
      "[MindSPONGE] Step: 1700, E_pot: -6115.774, E_kin: 9285.706, E_tot: 3169.9321, Temperature: 294.5184\n",
      "[MindSPONGE] Step: 1710, E_pot: -6343.5264, E_kin: 9626.301, E_tot: 3282.7744, Temperature: 305.32117\n",
      "[MindSPONGE] Step: 1720, E_pot: -6187.3774, E_kin: 9457.392, E_tot: 3270.0142, Temperature: 299.9638\n",
      "[MindSPONGE] Step: 1730, E_pot: -6252.286, E_kin: 9499.926, E_tot: 3247.6396, Temperature: 301.3129\n",
      "[MindSPONGE] Step: 1740, E_pot: -6185.2505, E_kin: 9372.885, E_tot: 3187.6343, Temperature: 297.28348\n",
      "[MindSPONGE] Step: 1750, E_pot: -6145.5117, E_kin: 9499.105, E_tot: 3353.5938, Temperature: 301.28687\n",
      "[MindSPONGE] Step: 1760, E_pot: -6007.631, E_kin: 9505.537, E_tot: 3497.9062, Temperature: 301.49084\n",
      "[MindSPONGE] Step: 1770, E_pot: -6238.6465, E_kin: 9575.92, E_tot: 3337.2734, Temperature: 303.7232\n",
      "[MindSPONGE] Step: 1780, E_pot: -6148.9893, E_kin: 9415.121, E_tot: 3266.1318, Temperature: 298.6231\n",
      "[MindSPONGE] Step: 1790, E_pot: -6114.186, E_kin: 9409.435, E_tot: 3295.2485, Temperature: 298.44275\n",
      "[MindSPONGE] Step: 1800, E_pot: -6213.543, E_kin: 9516.164, E_tot: 3302.621, Temperature: 301.82794\n",
      "[MindSPONGE] Step: 1810, E_pot: -6479.5615, E_kin: 9723.413, E_tot: 3243.8516, Temperature: 308.4013\n",
      "[MindSPONGE] Step: 1820, E_pot: -6199.7764, E_kin: 9275.0, E_tot: 3075.2236, Temperature: 294.17883\n",
      "[MindSPONGE] Step: 1830, E_pot: -6443.1875, E_kin: 9663.419, E_tot: 3220.2314, Temperature: 306.49844\n",
      "[MindSPONGE] Step: 1840, E_pot: -6474.4355, E_kin: 9555.467, E_tot: 3081.0312, Temperature: 303.0745\n",
      "[MindSPONGE] Step: 1850, E_pot: -6267.088, E_kin: 9372.191, E_tot: 3105.1035, Temperature: 297.2615\n",
      "[MindSPONGE] Step: 1860, E_pot: -6321.6064, E_kin: 9453.569, E_tot: 3131.963, Temperature: 299.8426\n",
      "[MindSPONGE] Step: 1870, E_pot: -6404.2065, E_kin: 9588.966, E_tot: 3184.7593, Temperature: 304.137\n",
      "[MindSPONGE] Step: 1880, E_pot: -6198.1006, E_kin: 9441.622, E_tot: 3243.5215, Temperature: 299.46362\n",
      "[MindSPONGE] Step: 1890, E_pot: -6159.1406, E_kin: 9401.905, E_tot: 3242.7646, Temperature: 298.20395\n",
      "[MindSPONGE] Step: 1900, E_pot: -6401.7495, E_kin: 9523.525, E_tot: 3121.776, Temperature: 302.0614\n",
      "[MindSPONGE] Step: 1910, E_pot: -6434.7793, E_kin: 9588.537, E_tot: 3153.7578, Temperature: 304.1234\n",
      "[MindSPONGE] Step: 1920, E_pot: -6224.161, E_kin: 9363.049, E_tot: 3138.8877, Temperature: 296.9715\n",
      "[MindSPONGE] Step: 1930, E_pot: -6388.14, E_kin: 9768.047, E_tot: 3379.9067, Temperature: 309.81702\n",
      "[MindSPONGE] Step: 1940, E_pot: -6184.5093, E_kin: 9544.836, E_tot: 3360.3267, Temperature: 302.73734\n",
      "[MindSPONGE] Step: 1950, E_pot: -6087.103, E_kin: 9493.592, E_tot: 3406.4888, Temperature: 301.112\n",
      "[MindSPONGE] Step: 1960, E_pot: -6025.9995, E_kin: 9399.992, E_tot: 3373.9927, Temperature: 298.14325\n",
      "[MindSPONGE] Step: 1970, E_pot: -6160.2344, E_kin: 9477.056, E_tot: 3316.8213, Temperature: 300.5875\n",
      "[MindSPONGE] Step: 1980, E_pot: -6193.536, E_kin: 9501.216, E_tot: 3307.6797, Temperature: 301.35382\n",
      "[MindSPONGE] Step: 1990, E_pot: -6407.917, E_kin: 9605.096, E_tot: 3197.1787, Temperature: 304.6486\n",
      "[MindSPONGE] Finished simulation at 2023-06-30 16:54:20\n",
      "[MindSPONGE] Simulation time: 4 minutes 17.6 seconds.\n",
      "--------------------------------------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<mindsponge.core.sponge.Sponge at 0x7f922af342e0>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "md.change_optimizer(opt)\n",
    "md.run(2000, callbacks=[run_info, cb_h5md])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mindspore-1.9",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  },
  "vscode": {
   "interpreter": {
    "hash": "768f82fbbece3f0acd424cda825de8aa44edbfaa38d8a3df4ff1437f7ae7861f"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
